package biz.impl;

import biz.HomePostsBiz;
import mapper.HomePostsMapper;
import org.apache.ibatis.session.SqlSession;
import org.example.bean.HomePostsInfo;
import org.example.bean.MemberInfo;
import org.example.bean.ReplyPostsInfo;

import java.util.List;

public class HomePostBizImpl implements HomePostsBiz {
    private HomePostsMapper hpm;
    private SqlSession session;

    public HomePostBizImpl(SqlSession session) {
        this.session = session;
        hpm = session.getMapper(HomePostsMapper.class);
    }

    @Override
    public List<HomePostsInfo> findHomePostsByForumsId(int id) {
        return hpm.findHomePostsByForumsId(id);
    }

    @Override
    public void saveHomePosts(HomePostsInfo hpi) {
        hpm.saveHomePosts(hpi);
        session.commit();
    }

    @Override
    public HomePostsInfo findHomePostById(int id) {
        return hpm.findHomePostById(id);
    }

    @Override
    public List<ReplyPostsInfo> findReplyPostsByHomePostId(int id) {
        return hpm.findReplyPostsByHomePostId(id);
    }

    @Override
    public void saveReply(ReplyPostsInfo rpi) {
        hpm.saveReply(rpi);
        session.commit();
    }

    @Override
    public MemberInfo findMemberByUserId(int userId) {
        return hpm.findMemberByUserId(userId);
    }

    @Override
    public void saveUserById(int id, int userId) {
        hpm.saveUserById(id,userId);
        session.commit();
    }

    @Override
    public void saveMemberByUserId(MemberInfo mi) {
        hpm.saveMemberByUserId(mi);
        session.commit();
    }
}
